package com.jiyejia.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Window;
import android.widget.ListView;

import com.jiyejia.R;
import com.jiyejia.adapter.ListAdapter;
import com.jiyejia.model.Order;
import com.jiyejia.utils.NetWorkManager;

/**
 * Created by zhoucong on 13-6-17.
 */
public class OrderActivity extends Activity{

    private ListView mListView;
    private ListAdapter adapter;
    private ArrayList<Order> list;
    private ProgressDialog pd;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.order);
        initView();
    }
    private void initView(){
        list = new ArrayList<Order>();
        mListView = (ListView)findViewById(R.id.orderlist);
        adapter = new ListAdapter(list,this);
        mListView.setAdapter(adapter);
        new GetDataTask().execute();

    }

    /**
     * 获取订单列表数据
     */
    private class GetDataTask extends AsyncTask<Void,Void,Void>{
    	

        @Override
		protected void onPreExecute() {
			super.onPreExecute();
			pd = ProgressDialog.show(OrderActivity.this, "请稍候", "数据获取中...");
		}

		@Override
        protected Void doInBackground(Void... voids) {
        	list = NetWorkManager.getInstance().postGetAllGoods();
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            adapter.setData(list);
            adapter.notifyDataSetChanged();
            pd.dismiss();
        }
    }
}
